﻿namespace OP10.ViewModels
{
    public class ST05CCDManagerViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        public ST05CCDManagerViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;

            //开启定时器任务
            DispatcherTimer dispatcherTimer = new DispatcherTimer();
            dispatcherTimer.Interval = TimeSpan.FromMilliseconds(200);
            dispatcherTimer.Tick += OnTick;
            dispatcherTimer.Start();
        }

        private void OnTick(object? sender, EventArgs e)
        {
            ST5bCheckOk = CCDPLCToPC_Global.ST5bCheckOk;
            ST5bCheckNg = CCDPLCToPC_Global.ST5bCheckNg;
            ST5bWorkDone = CCDPLCToPC_Global.ST5bWorkDone;
        }


        #region 事件


        private DelegateCommand _GoBackCommand;

        public DelegateCommand GoBackCommand =>
            _GoBackCommand ?? (_GoBackCommand = new DelegateCommand(ExecuteGoBackCommand));

        void ExecuteGoBackCommand()
        {
            NavigationParameters param = new NavigationParameters();
            param.Add("StationName", "ST05");
            _regionManager.RequestNavigate(PrismManager.MainViewRegionName, AppViews.ST05View, param);
        }

        private DelegateCommand _CCDAutoTriggerDownCmd;
        public DelegateCommand CCDAutoTriggerDownCmd =>
            _CCDAutoTriggerDownCmd ?? (_CCDAutoTriggerDownCmd = new DelegateCommand(ExecuteCCDAutoTriggerDownCmd));

        void ExecuteCCDAutoTriggerDownCmd()
        {
            CCDPCToPLC_Global.ST5bAutoTrigger = true;
        }


        private DelegateCommand _CCDAutoTriggerUpCmd;
        public DelegateCommand CCDAutoTriggerUpCmd =>
            _CCDAutoTriggerUpCmd ?? (_CCDAutoTriggerUpCmd = new DelegateCommand(ExecuteCCDAutoTriggerUpCmd));

        void ExecuteCCDAutoTriggerUpCmd()
        {
            CCDPCToPLC_Global.ST5bAutoTrigger = false;

        }



        private DelegateCommand _CCDPinBiCommand;
        public DelegateCommand CCDPinBiCommand =>
            _CCDPinBiCommand ?? (_CCDPinBiCommand = new DelegateCommand(ExecuteCCDPinBiCommand));

        void ExecuteCCDPinBiCommand()
        {
            CCDPCToPLC_Global.ST5DisableBT = true;
        }


        private DelegateCommand _CCDUnPinBiCommand;
        public DelegateCommand CCDUnPinBiCommand =>
            _CCDUnPinBiCommand ?? (_CCDUnPinBiCommand = new DelegateCommand(ExecuteCCDUnPinBiCommand));

        void ExecuteCCDUnPinBiCommand()
        {
            CCDPCToPLC_Global.ST5DisableBT = false;

        }


        private DelegateCommand _OpenLightCommand;
        public DelegateCommand OpenLightCommand =>
            _OpenLightCommand ?? (_OpenLightCommand = new DelegateCommand(ExecuteOpenLightCommand));

        void ExecuteOpenLightCommand()
        {
            CCDPCToPLC_Global.ST5LightBT = true;

        }

        private DelegateCommand _UnOpenLightCommand;
        public DelegateCommand UnOpenLightCommand =>
            _UnOpenLightCommand ?? (_UnOpenLightCommand = new DelegateCommand(ExecuteUnOpenLightCommand));

        void ExecuteUnOpenLightCommand()
        {
            CCDPCToPLC_Global.ST5LightBT = false;

        }

        private DelegateCommand _CCDCheckDownCmd;
        public DelegateCommand CCDCheckDownCmd =>
            _CCDCheckDownCmd ?? (_CCDCheckDownCmd = new DelegateCommand(ExecuteCCDCheckDownCmd));

        void ExecuteCCDCheckDownCmd()
        {
            CCDPCToPLC_Global.ST5CheckTrigger = true;
        }


        private DelegateCommand _CCDCheckUpCmd;
        public DelegateCommand CCDCheckUpCmd =>
            _CCDCheckUpCmd ?? (_CCDCheckUpCmd = new DelegateCommand(ExecuteCCDCheckUpCmd));

        void ExecuteCCDCheckUpCmd()
        {
            CCDPCToPLC_Global.ST5CheckTrigger = false;

        }




        private DelegateCommand<string> _CCDResultPingBiCmd;
        public DelegateCommand<string> CCDResultPingBiCmd =>
            _CCDResultPingBiCmd ?? (_CCDResultPingBiCmd = new DelegateCommand<string>(ExecuteCCDResultPingBiCmd));

        void ExecuteCCDResultPingBiCmd(string p)
        {
            switch (p)
            {
                case "桥丝长度检测屏蔽":

                    CCDPCToPLC_Global.ResultByPass[0] = true;
                    break;

                case "左焊点内距屏蔽":

                    CCDPCToPLC_Global.ResultByPass[1] = true;
                    break;
                case "右焊点内距屏蔽":

                    CCDPCToPLC_Global.ResultByPass[2] = true;
                    break;
                case "左焊点宽度屏蔽":

                    CCDPCToPLC_Global.ResultByPass[3] = true;
                    break;
                case "左焊点长度屏蔽":

                    CCDPCToPLC_Global.ResultByPass[4] = true;
                    break;
                case "右焊点宽度屏蔽":

                    CCDPCToPLC_Global.ResultByPass[5] = true;
                    break;
                case "右焊点长度屏蔽":

                    CCDPCToPLC_Global.ResultByPass[6] = true;
                    break;
                case "左右内距之和屏蔽":

                    CCDPCToPLC_Global.ResultByPass[7] = true;
                    break;
                case "焊接尾桥屏蔽":

                    CCDPCToPLC_Global.ResultByPass[8] = true;
                    break;
                case "焊点检测屏蔽":

                    CCDPCToPLC_Global.ResultByPass[9] = true;
                    break;

                default:
                    break;
            }


        }


        private DelegateCommand<string> _UnCCDResultPingBiCmd;
        public DelegateCommand<string> UnCCDResultPingBiCmd =>
            _UnCCDResultPingBiCmd ?? (_UnCCDResultPingBiCmd = new DelegateCommand<string>(ExecuteUnCCDResultPingBiCmd));

        void ExecuteUnCCDResultPingBiCmd(string p)
        {
            switch (p)
            {
                case "桥丝长度检测屏蔽":

                    CCDPCToPLC_Global.ResultByPass[0] = false;
                    break;

                case "左焊点内距屏蔽":

                    CCDPCToPLC_Global.ResultByPass[1] = false;
                    break;
                case "右焊点内距屏蔽":

                    CCDPCToPLC_Global.ResultByPass[2] = false;
                    break;
                case "左焊点宽度屏蔽":

                    CCDPCToPLC_Global.ResultByPass[3] = false;
                    break;
                case "左焊点长度屏蔽":

                    CCDPCToPLC_Global.ResultByPass[4] = false;
                    break;
                case "右焊点宽度屏蔽":

                    CCDPCToPLC_Global.ResultByPass[5] = false;
                    break;
                case "右焊点长度屏蔽":

                    CCDPCToPLC_Global.ResultByPass[6] = false;
                    break;
                case "左右内距之和屏蔽":

                    CCDPCToPLC_Global.ResultByPass[7] = false;
                    break;
                case "焊接尾桥屏蔽":

                    CCDPCToPLC_Global.ResultByPass[8] = false;
                    break;
                case "焊点检测屏蔽":

                    CCDPCToPLC_Global.ResultByPass[9] = false;
                    break;

                default:
                    break;
            }
        }



        #endregion


        #region 属性  
        private bool _ST5bWorkDone;
        public bool ST5bWorkDone
        {
            get { return _ST5bWorkDone; }
            set { SetProperty(ref _ST5bWorkDone, value); }
        }


        private bool _ST5bCheckOk;
        public bool ST5bCheckOk
        {
            get { return _ST5bCheckOk; }
            set { SetProperty(ref _ST5bCheckOk, value); }
        }
        private bool _ST5bCheckNg;
        public bool ST5bCheckNg
        {
            get { return _ST5bCheckNg; }
            set { SetProperty(ref _ST5bCheckNg, value); }
        }

        #endregion
    }
}
